package com.w5cschool.reflect;

/**
 * @author w5cSchool
 * @date 2021/11/7 18:01
 * description:
 * 测试class类的创建方式有哪些
 */
public class 创建class类的方式有哪些 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person p = new Student();
        System.out.println("p:"+ p);
        // 方式一：通过对象获得
        Class c1 = p.getClass();
        System.out.println(c1);

        // 方式二：通过forname获得
        Class c2 = Class.forName("com.w5cschool.reflect.Student");
        System.out.println(c2);

        // 方式三：通过类名.class 获得
        Class c3 = Student.class;
        System.out.println(c3);

        // 方式四：基本内置类型的包装类都有一个TYPE属性
        Class c4 = Integer.TYPE;
        System.out.println(c4);

        // 获得父亲类型
        Class c5 = c1.getSuperclass();
        System.out.println(c5);


    }
}

class Person{
    Person(){}
    String name;
}

class Student extends Person{
    public Student(){
        this.name = "学生";
    }
}

class Teacher extends Person{
    public Teacher(){
        this.name = "老师";
    }
}
